/**
 * @MultiConstantEventDispatchClosure.java  COPYRIGHT xiaojian
 * 
 * Created on 2017年10月10日 上午10:45:47
 */
package xiaojian.toolkit.ebus.closure;

import java.util.List;

import org.apache.commons.collections4.Closure;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import xiaojian.toolkit.ebus.EventBus;

/**
 * 
 * 触发多个事件。
 * 
 * @author <a href="mailto:cxj2000@gmail.com">xiaojian.cao</a>
 *
 */
public class MultiConstantEventDispatchClosure implements Closure {

	private static final Logger logger = LoggerFactory.getLogger(MultiConstantEventDispatchClosure.class);

	private EventBus eventBus;

	private List<String> constantEvents = null;

	public List<String> getConstantEvents() {
		return constantEvents;
	}

	public void setConstantEvents(List<String> constantEvents) {
		this.constantEvents = constantEvents;
	}

	/**
	 * @see org.apache.commons.collections.Closure#execute(java.lang.Object)
	 */
	public void execute(Object input) {
		if (null == input) {
			return;
		}

		if (constantEvents == null || constantEvents.size() == 0) {
			logger.warn("Events is null.");
			return;
		}

		for (String event : constantEvents) {
			if (logger.isDebugEnabled()) {
				logger.debug("fire event [" + event + "] <--> " + input);
			}
			eventBus.fireEvent(event, input);
		}
	}

	public EventBus getEventBus() {
		return eventBus;
	}

	public void setEventBus(EventBus eventBus) {
		this.eventBus = eventBus;
	}

}
